Page({
  data: {
     name:'',
     staffid:'',
     ctx: null,
     hasDraw:false, //默认没有画
     src:null,
     confirm :true,
     year:'',
     month:'',
     cont:'',
     moves:true,
    isScroll: true,
    infoss:'',
    otdate:'',
    jim:'',
    btn:false,
  },


onLoad(query) {
 
  //?cont='+that.otdate+'& contentStr='+ that.contentStr
   this.setData({
     otdate:query.cont,
     infoss:query.infoss,
     jim:query.jim,
   });

//console.log('query'+query);
console.log('cont-'+query.cont);
console.log('infoss-'+query.infoss);
console.log('jim-'+query.jim);


var ctx = dd.createCanvasContext('hand');
    ctx.setStrokeStyle('blue');
       ctx.setLineWidth(3);

       this.setData({
        ctx: ctx,
      });
  
var that=this;

  dd.getStorage({
  key: 'staffid',
  success: function(res) 
  { 

  that.setData({

   staffid:res.data

  });
  }});

   dd.getStorage({
  key: 'name',
  success: function(res) {

  that.setData({
   name:res.data

  });}});
  

 
  
  },


  

   start: function(e) {
    var ctx = this.data.ctx;
    ctx.moveTo(e.touches[0].x, e.touches[0].y);
    this.setData({
      ctx: ctx,
      hasDraw : true, //要签字了
    });
   },
  move: function(e) {
    var x = e.touches[0].x;
    var y = e.touches[0].y;
    var ctx = this.data.ctx;
    ctx.setLineWidth(3);
    ctx.lineTo(x, y);
    ctx.stroke();
    ctx.setLineCap('round');
    ctx.draw(true);
    ctx.moveTo(x, y);
  },
  reSigna: function() { //重新画

var that = this;
    var ctx= that.data.ctx;
    ctx.draw(); //清空画布
    that.setData({
      hasDraw: false, //没有画
      src: null
    });



    
  },


  signoka: function () {

    var that = this;
    if(!that.data.hasDraw){
      console.log("签字是空白的 没有签字")
    }else{

      that = this;
      that.setData({

        btn:true,

      });
      var ctx = that.data.ctx;
   
   
   ctx.toTempFilePath({
  
  success(res) {

   that.setData({
          src: res.filePath,
   });

    console.log(res);  
 
  
     console.log('constr'+that.data.contentStr+'cont'+that.data.otdate+'staffid'+that.data.staffid);
     dd.uploadFile({
      url:'http://ding.tida-lighting.com/api/user/overtime',
      fileType: 'image',
      fileName: 'img',
      filePath:that.data.src, 
      formData: { 
        
        
                  'staffid':that.data.staffid,
                  'infos':that.data.infoss,
                  'cont':that.data.otdate,
      
      },
      

      success: function (res) {
      dd.showToast({
      content: '提交成功'
    });

         //dd.navigateTo({ url:'../WorkTime/WorkTime' });
      dd.navigateBack({
      delta: 3
     });
        
      },fail:function(data){
        
        dd.showToast({
          content: '提交失败，请重新签名提交',
        
        })
        console.log(data);
         console.log(that.data.src);
      }
    });


  }
                   });

 

    }
  },
 
});
